<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title>layPage快速使用</title>
		<link rel="stylesheet" href="./lib/layui/css/layui.css" media="all">
		<script src="./js/jquery-3.3.1.min.js" type="text/javascript" charset="utf-8"></script>
	</head>
	<body>
		<div class="newsList"></div>
		<!-- 模板容器 -->
		<div id="view" class="clearfix"></div>
		<!-- 分页容器 -->
		<div id="test1"></div>
		<!-- 模板 -->
		<script id="demo" type="text/html">
			{{#  layui.each(d, function(index, item){ }}
		  <div class="item">
			
			<div class="con clearfix">
				<div class="fl w55">
					<ul>
						<li><span>{{ item.patName }}</span></li>
					</ul>
				</div>
				
			</div>
			
			 </div>
		  {{#  }); }}
		  {{#  if(d.length === 0){ }}
			无数据
		  {{#  } }}  
	</script>
		<script src="./lib/layui/layui.js"></script>
		<script>
			layui.use(['laypage', 'laytpl'], function () {
				var laypage = layui.laypage;
				var laytpl = layui.laytpl;
				var param = JSON.stringify({
					"body": {
						"isHospital ": 1,
						"departmentId": "60",
						"patientName": "",
						"admid": ""
						// "currPage": obj.curr,
						// "pageSize": obj.limit
						// "currPage": 1,
						// "pageSize": 8
					},
					"header": {},
					"token": {}
				});
				$.ajax({
					'type': 'post',
					'url': 'http://192.168.0.100:8070/service-patient/patient/viewPatientList',
					'data': param,
					'dataType': 'json',
					'contentType': "application/json",
					'success': function(data) {
						console.log(data);
						console.log(data.data.total);
						var len = data.data.total;
						var list = data.data.list;
						
						
						laypage.render({
							elem: 'test1',
							count: len, //数据总数，从服务端得到
							curr: 1, //起始页
							// groups: 5,
							limit: 2,
							limits:[8],
							layout: ['count', 'prev', 'page', 'next', 'limit', 'skip'],
							jump: function(obj, first) {
								//obj包含了当前分页的所有参数，比如：
								console.log("当前页码" + obj.curr); //得到当前页，以便向服务端请求对应页的数据。
								console.log("当前显示" + obj.limit + "条"); //得到每页显示的条数
									//根据当前页请求和渲染模
									
								thisData = list.concat().splice(obj.curr*obj.limit - obj.limit, obj.limit);
								console.log(thisData);	
								
								
								var getTpl = demo.innerHTML,
									view = document.getElementById('view');
								laytpl(getTpl).render(thisData, function(html) {
									view.innerHTML = html;
								});
									
								//首次不执行
								if (!first) {
									//do something

								}
							}
							
						});
						
					},
					
					'error': function(res) {
						console.log(res);
					}
				});
			});
		</script>
</html>
<!-- 
 
 
 
 
 -->